package miravalles.chip;

import java.util.Random;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.RemoteViews;

public class BoteWidget extends AppWidgetProvider {

	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds) {
		
		ComponentName thisWidget = new ComponentName(context,BoteWidget.class);		 
		int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
		
		for (int widgetId : allWidgetIds) {
		      RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
			          R.layout.widget_layout);
		      SharedPreferences pref=PreferenceManager.getDefaultSharedPreferences(context);
		      String bote=pref.getString("bote","0");
		      String tituloBote=context.getResources().getString(R.string.nombreBote0);
		      tituloBote=pref.getString("nombreBote0", tituloBote);
		      remoteViews.setTextViewText(
		    		  R.id.bote, bote);
		      remoteViews.setTextViewText(
		    		  R.id.tituloBote, tituloBote);
		      
		      appWidgetManager.updateAppWidget(widgetId, remoteViews);		      
			  }
	}
}
